package com.flnet.web.controller.foxwash;

import com.flnet.common.annotation.Log;
import com.flnet.common.base.AjaxResult;
import com.flnet.common.enums.BusinessType;
import com.flnet.common.page.TableDataInfo;
import com.flnet.common.utils.UUIDUtils;
import com.flnet.common.utils.poi.ExcelUtil;
import com.flnet.foxwash.domain.WPay;
import com.flnet.foxwash.domain.WVendor;
import com.flnet.foxwash.service.IWPayService;
import com.flnet.framework.util.ShiroUtils;
import com.flnet.framework.web.base.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 支付 信息操作处理
 * 
 * @author flnet
 * @date 2019-03-20
 */
@Controller
@RequestMapping("/foxwash/wPay")
public class WPayController extends BaseController
{
    private String prefix = "foxwash/wPay";
	
	@Autowired
	private IWPayService wPayService;
	
	@RequiresPermissions("foxwash:wPay:view")
	@GetMapping()
	public String wPay()
	{
	    return prefix + "/wPay";
	}
	
	/**
	 * 查询支付列表
	 */
	@RequiresPermissions("foxwash:wPay:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WPay wPay)
	{
		startPage();
        List<WPay> list = wPayService.selectWPayList(wPay);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出支付列表
	 */
	@RequiresPermissions("foxwash:wPay:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WPay wPay)
    {
    	List<WPay> list = wPayService.selectWPayList(wPay);
        ExcelUtil<WPay> util = new ExcelUtil<WPay>(WPay.class);
        return util.exportExcel(list, "wPay");
    }
	
	/**
	 * 新增支付
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存支付
	 */
	@RequiresPermissions("foxwash:wPay:add")
	@Log(title = "支付", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WPay wPay)
	{
		wPay.setUuid(UUIDUtils.getUUID());
		wPay.setCreator(ShiroUtils.getUserId());
		return toAjax(wPayService.insertWPay(wPay));
	}

	/**
	 * 修改支付
	 */
	@GetMapping("/edit/{payId}")
	public String edit(@PathVariable("payId") Long payId, ModelMap mmap)
	{
		WPay wPay = wPayService.selectWPayById(payId);
		mmap.put("wPay", wPay);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存支付
	 */
	@RequiresPermissions("foxwash:wPay:edit")
	@Log(title = "支付", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WPay wPay)
	{
		wPay.setModifier(ShiroUtils.getUserId());
		return toAjax(wPayService.updateWPay(wPay));
	}
	
	/**
	 * 删除支付
	 */
	@RequiresPermissions("foxwash:wPay:remove")
	@Log(title = "支付", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(wPayService.deleteWPayByIds(ids));
	}

	/**
	 * 服务状态修改
	 */
	@Log(title = "支付管理", businessType = BusinessType.UPDATE)
	@RequiresPermissions("foxwash:wPay:edit")
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(WPay wPay)
	{
		return toAjax(wPayService.changeStatus(wPay));
	}
}
